# -*- coding: utf-8  -*-
#!/usr/local/bin/python

__author__ = 'jian.yao'

from cm.appserver.constants import AppServerOrderType
from misc.backend import BaseManager
class AppServerManager(BaseManager):
    def __init__(self):
        _order_type = AppServerOrderType
        BaseManager.__init__(self, _model = AppServer, _order_type = _order_type)

    def __save__(self, _object, _commit = True, **kargs):
        if not _object:
            return None

        if '_id' in kargs:
            _object.id = kargs['_id']
        if '_idc' in kargs:
            _object.idc = kargs['_idc']
        if '_host' in kargs:
            _object.host = kargs['_host']
        if '_port' in kargs:
            _object.port = kargs['_port']
        if '_lan_ip' in kargs:
            _object.lan_ip = kargs['_lan_ip']
        if '_wan_ip' in kargs:
            _object.wan_ip = kargs['_wan_ip']
        if '_public_key' in kargs:
            _object.public_key = kargs['_public_key']
        if '_secret_key' in kargs:
            _object.secret_key = kargs['_secret_key']
        if '_server_type' in kargs:
            _object.server_type = kargs['_server_type']
        if '_creator' in kargs:
            _object.creator = kargs['_creator']
        if '_create_time' in kargs:
            _object.create_time = kargs['_create_time']
        if '_last_editor' in kargs:
            _object.last_editor = kargs['_last_editor']
        if '_status' in kargs:
            _object.status = kargs['_status']
        if '_description' in kargs:
            _object.description = kargs['_description']
        if '_last_update' in kargs:
            _object.last_update = kargs['_last_update']

        if _commit:
            _object.save()

        return _object